package com.liuzy.crawler;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author liuzy
 * @since 2015年9月19日
 */
public class Config {
	public static String cacheDir = "D:/_DownLoad/";
	public static int cacheSize = 2147483647;
	public static int cacheCount = 25;
	public static boolean cacheAutoClear = true;
	public static boolean cacheLog = false;

	public static int scanSize = 2147483647;
	public static int scanCount = 5;
	public static boolean sacnDelFile = true;
	public static boolean scanLog = false;

	public static String dlDir = "D:/_DownLoad/_cache/";
	public static int dlSize = 2147483647;
	public static int dlcount = 25;
	public static boolean dlBysite = true;
	public static boolean dlRename = false;
	public static boolean dlFast = true;
	public static boolean dlLog = true;

	public static boolean checkVersion = true;
	public static boolean autoUpdate = false;
	public static boolean consoleLog = true;

	private Config() {

	}

	public static void load() {
		try {
			InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
			Properties props = new Properties();
			props.load(inputStream);

			Config.cacheDir = props.getProperty("cacheDir");
			Config.cacheSize = Integer.parseInt(props.getProperty("cacheSize"));
			Config.cacheCount = Integer.parseInt(props.getProperty("cacheCount"));
			Config.cacheAutoClear = "true".equals(props.getProperty("cacheAutoClear"));
			Config.cacheLog = "true".equals(props.getProperty("cacheLog"));

			Config.scanSize = Integer.parseInt(props.getProperty("cacheSize"));
			Config.scanCount = Integer.parseInt(props.getProperty("scanCount"));
			Config.sacnDelFile = "true".equals(props.getProperty("saveBySite"));
			Config.scanLog = "true".equals(props.getProperty("saveBySite"));

			Config.dlDir = props.getProperty("cacheDir");
			Config.dlSize = Integer.parseInt(props.getProperty("dlSize"));
			Config.dlcount = Integer.parseInt(props.getProperty("dlcount"));
			Config.dlBysite = "true".equals(props.getProperty("dlBysite"));
			Config.dlRename = "true".equals(props.getProperty("dlRename"));
			Config.dlFast = "true".equals(props.getProperty("dlFast"));
			Config.dlLog = "true".equals(props.getProperty("dlLog"));

			Config.checkVersion = "true".equals(props.getProperty("checkVersion"));
			Config.autoUpdate = "true".equals(props.getProperty("autoUpdate"));
			Config.consoleLog = "true".equals(props.getProperty("consoleLog"));

			if (inputStream != null)
				inputStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
